package snippet;
import java.util.*;
public class 组合 {
	List<List<Integer>> result = new ArrayList<>();
	List<Integer> item = new ArrayList<>();
    public List<List<Integer>> combine(int n, int k) {
    	
    	backtracking(n, k, 1);
    	System.out.println(result);
    	return result;
    }
    
    public void backtracking(int n, int k, int index) {
    	if(item.size() == k) {
    		result.add(new ArrayList<>(item));
    		return;
    	}
    	for(int i = index; i <= n; i++) {
    		item.add(i);
    		backtracking(n, k, i + 1);
    		item.remove(item.size() - 1);
    	}
    	
    }
    
    public static void main(String[] args) {
		new 组合().combine(20, 19);
    	
	}
}
